#include "main_header.h"

int recvn(int netfd,void *buf,int length){
    char *p = (char *)buf;
    int total = 0;

    while(total < length){
        int res = recv(netfd,total+p,length - total, 0);
        total+=res;
    }
    return total;
}

int recv_command(int netfd){
    train_t train;
  //  char command_name[50];
  //  bzero(command_name,sizeof(command_name));
    bzero(train.data,sizeof(train.data));
    recvn(netfd,&train.type,sizeof(train.type));
    recvn(netfd,&train.length,sizeof(train.length));
    recvn(netfd,train.data,train.length);
    /* memcpy(command_name,train.data,train.length); */
    return train.type;
}


